﻿<%@ Page Language="C#" %>

<%
    var node = Newtonsoft.Json.JsonConvert.DeserializeObject<string>(this.Request.QueryString["id"]);
    var rootPath = this.Server.MapPath("../../").TrimEnd('\\');
    var path = node == "\\" ? rootPath : System.IO.Path.Combine(rootPath, node.TrimStart('\\'));

    var files = System.IO
        .Directory
        .GetDirectories(path)
        .Concat(System.IO.Directory.GetFiles(path))
        .Select(x =>
        {
            var name = System.IO.Path.GetFileName(x);
            var parentId = node;
            return new
            {
                Id = parentId + "\\" + name,
                Name = name,
                ParentId = parentId,
                leaf = System.IO.Path.HasExtension(x)
            };
        });
%>

<%= Newtonsoft.Json.JsonConvert.SerializeObject(new { items = files }) %>